﻿
using QRCoder;
using System;
using System.Drawing;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace wpf_print.view
{
    internal class CreatCodeQR
    {
        public static System.Windows.Controls.Image CreateQRCode(string QRCode, Thickness thickness)
        {
            System.Windows.Controls.Image img = new();
            QRCodeGenerator qrGenerator = new();
            QRCodeData qrCodeData = qrGenerator.CreateQrCode(QRCode, QRCodeGenerator.ECCLevel.Q);
            QRCode qrCode = new(qrCodeData);
            Bitmap qrCodeImage = qrCode.GetGraphic(20);
            IntPtr hBitmap = qrCodeImage.GetHbitmap();
            ImageSource wpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                hBitmap,
                IntPtr.Zero,
                Int32Rect.Empty,
                BitmapSizeOptions.FromEmptyOptions());
            img.Source = wpfBitmap;
            img.Width = 80;
            img.Height = 80;
            img.Margin = thickness;
            return img;
        }
    }
}
